function seeObject(direction, distance)
	return sonarReading(direction) < distance
end

function seeObject(distance)
	return sonarReading(1) < distance
end

function retreatRight()
	backward(A)
	stop(B)
end

function retreatLeft()
	backward(B)
	stop(A)
end

function stop()
	stop(A)
	stop(B)
end

function avoid()
	if sonarReading(3) > sonarReading(2) then
		retreatLeft()
	else
		retreatRight()
	end
end

function avoid_main()
	if seeObject(40) then
		avoid()
	else
		stop()
	end
end

repeat
	avoid_main()
until isPressed(ESCAPE)



